package com.datastructure.test.minnumberdisappeared;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class MinNumberDisappeared {

    public static void main(String[] args) {

    }

    public int minNumberDisappeared (int[] nums) {
        // write code here
        Arrays.sort(nums);
        int length = nums.length;
        int max = nums[length -1];
        if(max<0){
            return 1;
        }
        int indexI=0;
        for (int i = 0; i < length; i++) {
            if(nums[i]==0||nums[i]==1){
                indexI=i;
                break;
            }
            if(nums[i]>1){
                return Math.min(1,nums[i]-1);
            }
        }
        for(int j = indexI; j< length -1; j++){
            if(nums[j+1]!=nums[j]+1){
                return nums[j]+1;
            }
        }
        return max+1;
    }
}
